import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Router, Routes} from '@angular/router';

@Component({
  selector: 'app-user-list',
  templateUrl: './user-list.component.html',
  styleUrls: ['./user-list.component.css']
})
export class UserListComponent implements OnInit {
  url = 'http://127.0.0.1:8080/lx/';
   userList = [];
  constructor(private http: HttpClient,
              private roter: Router) { }

  ngOnInit() {
    this.getUserList();
  }
  getUserList() {
    this.http.get(this.url + 'findAllByIfDelete').subscribe(v => {
      if (v['code'] === 0) {
        this.userList = v['data'];
        console.log(v['data']);
      } else {
        alert('获取失败');
      }
    });
  }

  /**
   * 跳转编辑页面
   */
  edit(id){
    if(id){
      this.roter.navigate(['userAdd'],{queryParams: {id: id}});
    }else {
      this.roter.navigate(['userAdd']);
    }
  }
}
